package org.jeecg.modules.nongjt.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.ClientException;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DySmsEnum;
import org.jeecg.common.util.DySmsHelper;

import org.jeecg.modules.nongjt.user.api.ValidateCodeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sms")
public class SMSController {

    @GetMapping("/test")
    public Result<?> smsTest(String mobile) throws ClientException, com.aliyuncs.exceptions.ClientException {
        JSONObject obj = new JSONObject();
        obj.put("code", ValidateCodeUtils.generateValidateCode(6));
        //将验证码存入Redis（设置失效时间），用于登录或注册时判断相等
        boolean rs = DySmsHelper.sendSms(mobile, obj, DySmsEnum.REGISTER_TEMPLATE_CODE);
        if(rs){
            return Result.OK("发送成功",2000);
        }
        return Result.error("验证码发送失败");
    }
}